<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      /*
      //使用构造函数
      function SuperType(name) {
        this.name = name;
      }
      //原型方法
      SuperType.prototype.say = function () {
        console.log(this.name);
      };

      let instance = new SuperType('Tom');
      instance.say();
      */

      //使用class
      class SuperType { //注意class不能重名的问题
        constructor(name) {
          //构造函数
          this.name = name;
        }
        say() {
          //原型方法
          console.log(this.name);
        }
      }
      let instance = new SuperType('Jack');
      instance.say();

      console.log(typeof SuperType);
      console.log(instance.__proto__ === SuperType.prototype);
      console.log(instance.constructor === SuperType);

      console.log(instance.hasOwnProperty("say"));//true
      console.log(instance.__proto__.hasOwnProperty("say"));//false

      //思考：实例化出来的两个对象的，属性是各自的还是共享的？方法是各自的还是共享的？
      let instance2 = new SuperType('Lily');
      console.log(instance.name == instance2.name);//false
      console.log(instance.say == instance2.say);//true 共享
      
    </script>
  </body>
</html>
